<template>
  <view>
    <my-search :bgcolor="'#c00000'" :radius="17" @click="gotoSearch"></my-search>
    <view class="scroll_view_container">
      <!-- 左边 -->
      <view class="left_scroll_view">
        <scroll-view scroll-y="true" :style="{height: wh+'px'}">
          <block v-for="(item,i) in cateList" :key="i">
            <!-- 注意样式渲染 -->
            <view :class="['left_scroll_view_item',i === active ? 'active' : '']" @click="handleActive(i)">{{item.cat_name}}</view>
          </block>
        </scroll-view>
      </view>
      <!-- 左边 -->
      <!-- 右边 -->
      <view class="right_scroll_view">
        <scroll-view scroll-y="true" :style="{height: wh+'px'}" :scroll-top="scrollTop">
          <!-- 标题 -->
          <view class="yyy" v-for="(item2,i2) in cateList2" :key="i2" >
            <view class="yy_title">/ {{item2.cat_name}} /</view>
            <view class="yy_list">
              <navigator class="yy_item" v-for="(item3,i3) in item2.children" :key="i3" :url="'/subpkg/goods_list/goods_list?cid='+item3.cat_id">
                <image :src="item3.cat_icon" class="yy_item_img1" mode="widthFix"></image>
                <view class="">
                  <text class="txt">{{item3.cat_name}}</text>
                </view>
              </navigator>
            </view>
          </view>
        </scroll-view>
      </view>
      <!-- 右边 -->
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        wh:0,
        cateList:[],
        active:0,
        cateList2:[],
        scrollTop:[]
      };
    },
    onLoad() {
      const sysInfo = uni.getSystemInfoSync()
      // console.log(sysInfo.windowHeight)
      this.wh=sysInfo.windowHeight - 50
      this.getCateList()
    },
    methods:{
     async getCateList(){
       const res = await uni.$http.get('/api/public/v1/categories')
       // console.log(res)
       if(res.data.meta.status !== 200) return uni.$showMsg()
       this.cateList = res.data.message
       this.cateList2 = res.data.message[0].children
      },
      handleActive(i){
        this.active=i
        this.cateList2 = this.cateList[i].children
        this.scrollTop = this.scrollTop === 0 ? 1 : 0
      },
      // 搜索事件
      gotoSearch(){
        // console.log('ok')
        uni.navigateTo({
          url:'/subpkg/search/search'
        })
      }
    }
    
  }
</script>

<style lang="scss">
.scroll_view_container{
  display: flex;
  .left_scroll_view{
    width: 120px;
    .left_scroll_view_item{
      line-height: 60px;
      text-align: center;
      background-color: #f7f7f7;
      font-size: 12px;
      &.active{
        background-color: #FFFFFF;
        position: relative;
        &::before{
          content: '';
          display: block;
          width: 3px;
          height: 30px;
          background-color: #c00000;
          position: absolute;
          top: 50%;
          transform: translateY(-50%);
        }
      }
    }
  }
  .right_scroll_view{
    width: 100%;
    .yy_title{
      text-align: center;
      font-size: 14px;
      font-weight: bold;
      padding: 10px 0;
    }
    .yy_list{
      display: flex;
      flex-wrap: wrap;
      padding-left: 15px;
      .yy_item{
        width: 33.3%;
        display: flex;
        flex-direction: column;
        align-items: center;
        .yy_item_img1{
          width: 70px;
        }
        .txt{
          font-size: 12px
        }
      }
    }
  }
}
    
</style>
